package com.mitake.servlet;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;

import com.mitake.parse.DayK;
import com.mitake.parse.Stock;
import com.mitake.parse.DayK.DayKItem;
import com.mitake.task.CompareProcess;
import com.mitake.task.QuoteCompareTask;
import com.mitake.task.dayK.DayKCompareProcess;
import com.mitake.utils.ExcelUtil;
import com.mitake.utils.Util;

public class MonitorActionServlet extends HttpServlet
{
	private static final long serialVersionUID = 1L;
	private static final String CONTENT_TYPE = "text/html; charset=UTF-8";

	public MonitorActionServlet()
	{
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		response.setContentType(CONTENT_TYPE);
		request.setCharacterEncoding(response.getCharacterEncoding());
		
		String event = request.getParameter("event");
		String src = request.getParameter("src");
		String data = "";
		
		QuoteCompareTask quoteCompareTask = QuoteCompareTask.getInstance();
		
		if(event.equals("s"))
		{
			ServletContext context = getServletContext();
			String rootPath = context.getRealPath("");
			/**
			 * 取得詢問報告間隔時間
			 */
			quoteCompareTask.setRunInterval(Util.getRunInterval(rootPath));
			/**
			 * 取得商品
			 */
			quoteCompareTask.setStockList(Util.getStock(rootPath));
			/**
			 * Log路径
			 */
			File file = new File(rootPath + "/log/");

			if(!file.exists())
			{
				file.mkdirs();
			}
			
			quoteCompareTask.setLogPath(rootPath + "/log/");
			/**
			 * 取得各机房IP
			 */
			quoteCompareTask.start(Util.getHost(rootPath));
			
			data = "{\"code\":\"00000\",\"message\":\"程序启动中\"}";
		}
		else if(event.equals("e"))
		{
			quoteCompareTask.stop();
			
			data = "{\"code\":\"00000\",\"message\":\"程序停止中\"}";
		}
		else if(event.equals("g"))
		{
			String[][] status = quoteCompareTask.getAllSocketStatus();

			StringBuilder t = new StringBuilder();
			
			if(status != null)
			{
				t.append("[");
				
				for(int i = 0 ; i < status.length ; i++)
				{
					t.append("{");
					t.append("\"ip\":\"").append(status[i][0]).append("\",");
					t.append("\"status\":\"").append(status[i][1]).append("\"");
					t.append("},");
				}
				
				t.setLength(t.length() - 1);
				t.append("]");
			}
			
			String[] count = quoteCompareTask.getTelegramCount();
			
			StringBuilder tmp = new StringBuilder();
			tmp.append("{");
			tmp.append("\"code\":\"00000\",");
			tmp.append("\"message\":\"ok\",");
			tmp.append("\"running\":");
			tmp.append((quoteCompareTask.isRunning() ? "\"true\"" : "\"false\"")).append(",");
			tmp.append("\"w\":\"");
			tmp.append(count[0]).append("\",");
			tmp.append("\"r\":\"");
			tmp.append(count[1]).append("\",");
			tmp.append("\"host\":");
			tmp.append(t.length() > 0 ? t : "\"\"").append(",");
			
			ArrayList<Stock[]> push = CompareProcess.store;
			
			if(push.size() > 0)
			{
				int index = Integer.parseInt(src);
				
				if(push.size() > 0)
				{
					int sendCount = 0;
					tmp.append("\"push\":[");

					for(int i = index + 1 ; i < push.size() && sendCount < 20 ; i++, sendCount++)
					{
						if(i > (index + 1))
						{
							tmp.append(",");
						}
						
//						tmp.append("[");
						
						Stock[] list = push.get(i);
						
						Stock one = list[0];

						for(int j = 1 ; j < list.length ; j++)
						{
							if(j != 1)
							{
								tmp.append(",");
							}
							
							tmp.append("{");

							Stock stock = list[j];
							
							tmp.append("\"host\":\"").append(stock.host).append("\",");
							tmp.append("\"responseTime\":\"").append(stock.responseTime).append("\",");
							tmp.append("\"id\":\"").append(stock.id).append("\",");
							tmp.append("\"name\":\"").append(stock.name).append("\",");

							
							tmp.append("\"status\":{\"v\":\"").append(stock.status).append("\",\"d\":\"").append(checkDiff(one.status)).append("\"},");
							tmp.append("\"datetime\":{\"v\":\"").append(stock.datetime).append("\",\"d\":\"").append(checkDiff(one.datetime)).append("\"},");
							tmp.append("\"market\":{\"v\":\"").append(stock.market).append("\",\"d\":\"").append(checkDiff(one.market)).append("\"},");
							tmp.append("\"subtype\":{\"v\":\"").append(stock.subtype).append("\",\"d\":\"").append(checkDiff(one.subtype)).append("\"},");
							tmp.append("\"lastPrice\":{\"v\":\"").append(stock.lastPrice).append("\",\"d\":\"").append(checkDiff(one.lastPrice)).append("\"},");
							tmp.append("\"highPrice\":{\"v\":\"").append(stock.highPrice).append("\",\"d\":\"").append(checkDiff(one.highPrice)).append("\"},");
							tmp.append("\"lowPrice\":{\"v\":\"").append(stock.lowPrice).append("\",\"d\":\"").append(checkDiff(one.lowPrice)).append("\"},");
							tmp.append("\"openPrice\":{\"v\":\"").append(stock.openPrice).append("\",\"d\":\"").append(checkDiff(one.openPrice)).append("\"},");
							tmp.append("\"preClosePrice\":{\"v\":\"").append(stock.preClosePrice).append("\",\"d\":\"").append(checkDiff(one.preClosePrice)).append("\"},");
							tmp.append("\"changeRate\":{\"v\":\"").append(stock.changeRate).append("\",\"d\":\"").append(checkDiff(one.changeRate)).append("\"},");
							tmp.append("\"volume\":{\"v\":\"").append(stock.volume).append("\",\"d\":\"").append(checkDiff(one.volume)).append("\"},");
							tmp.append("\"nowVolume\":{\"v\":\"").append(stock.nowVolume).append("\",\"d\":\"").append(checkDiff(one.nowVolume)).append("\"},");
							tmp.append("\"turnoverRate\":{\"v\":\"").append(stock.turnoverRate).append("\",\"d\":\"").append(checkDiff(one.turnoverRate)).append("\"},");
							tmp.append("\"limitUP\":{\"v\":\"").append(stock.limitUP).append("\",\"d\":\"").append(checkDiff(one.limitUP)).append("\"},");
							tmp.append("\"limitDown\":{\"v\":\"").append(stock.limitDown).append("\",\"d\":\"").append(checkDiff(one.limitDown)).append("\"},");
							tmp.append("\"averageValue\":{\"v\":\"").append(stock.averageValue).append("\",\"d\":\"").append(checkDiff(one.averageValue)).append("\"},");
							tmp.append("\"change\":{\"v\":\"").append(stock.change).append("\",\"d\":\"").append(checkDiff(one.change)).append("\"},");
							tmp.append("\"amount\":{\"v\":\"").append(stock.amount).append("\",\"d\":\"").append(checkDiff(one.amount)).append("\"},");
							tmp.append("\"volumeRatio\":{\"v\":\"").append(stock.volumeRatio).append("\",\"d\":\"").append(checkDiff(one.volumeRatio)).append("\"},");
							tmp.append("\"buyPrice\":{\"v\":\"").append(stock.buyPrice).append("\",\"d\":\"").append(checkDiff(one.buyPrice)).append("\"},");
							tmp.append("\"sellPrice\":{\"v\":\"").append(stock.sellPrice).append("\",\"d\":\"").append(checkDiff(one.sellPrice)).append("\"},");
							tmp.append("\"buyVolume\":{\"v\":\"").append(stock.buyVolume).append("\",\"d\":\"").append(checkDiff(one.buyVolume)).append("\"},");
							tmp.append("\"sellVolume\":{\"v\":\"").append(stock.sellVolume).append("\",\"d\":\"").append(checkDiff(one.sellVolume)).append("\"},");
							tmp.append("\"totalValue\":{\"v\":\"").append(stock.totalValue).append("\",\"d\":\"").append(checkDiff(one.totalValue)).append("\"},");
							tmp.append("\"flowValue\":{\"v\":\"").append(stock.flowValue).append("\",\"d\":\"").append(checkDiff(one.flowValue)).append("\"},");
							tmp.append("\"netAsset\":{\"v\":\"").append(stock.netAsset).append("\",\"d\":\"").append(checkDiff(one.netAsset)).append("\"},");
							tmp.append("\"pe\":{\"v\":\"").append(stock.pe).append("\",\"d\":\"").append(checkDiff(one.pe)).append("\"},");
							tmp.append("\"roe\":{\"v\":\"").append(stock.roe).append("\",\"d\":\"").append(checkDiff(one.roe)).append("\"},");
							tmp.append("\"capitalization\":{\"v\":\"").append(stock.capitalization).append("\",\"d\":\"").append(checkDiff(one.capitalization)).append("\"},");
							tmp.append("\"circulatingShares\":{\"v\":\"").append(stock.circulatingShares).append("\",\"d\":\"").append(checkDiff(one.circulatingShares)).append("\"},");
							tmp.append("\"buyPricesTmp\":{\"v\":\"").append(stock.buyPricesTmp).append("\",\"d\":\"").append(checkDiff(one.buyPricesTmp)).append("\"},");
							tmp.append("\"sellPricesTmp\":{\"v\":\"").append(stock.sellPricesTmp).append("\",\"d\":\"").append(checkDiff(one.sellPricesTmp)).append("\"},");
							tmp.append("\"buyVolumesTmp\":{\"v\":\"").append(stock.buyVolumesTmp).append("\",\"d\":\"").append(checkDiff(one.buyVolumesTmp)).append("\"},");
							tmp.append("\"buySingleVolumesTmp\":{\"v\":\"").append(stock.buySingleVolumesTmp).append("\",\"d\":\"").append(checkDiff(one.buySingleVolumesTmp)).append("\"},");
							tmp.append("\"sellVolumesTmp\":{\"v\":\"").append(stock.sellVolumesTmp).append("\",\"d\":\"").append(checkDiff(one.sellVolumesTmp)).append("\"},");
							tmp.append("\"sellSingleVolumesTmp\":{\"v\":\"").append(stock.sellSingleVolumesTmp).append("\",\"d\":\"").append(checkDiff(one.sellSingleVolumesTmp)).append("\"},");
							tmp.append("\"amplitudeRate\":{\"v\":\"").append(stock.amplitudeRate).append("\",\"d\":\"").append(checkDiff(one.amplitudeRate)).append("\"},");
							tmp.append("\"receipts\":{\"v\":\"").append(stock.receipts).append("\",\"d\":\"").append(checkDiff(one.receipts)).append("\"},");
							tmp.append("\"tradeTickTmp\":{\"v\":\"").append(stock.tradeTickTmp).append("\",\"d\":\"").append(checkDiff(one.tradeTickTmp)).append("\"},");
							tmp.append("\"upCount\":{\"v\":\"").append(stock.upCount).append("\",\"d\":\"").append(checkDiff(one.upCount)).append("\"},");
							tmp.append("\"sameCount\":{\"v\":\"").append(stock.sameCount).append("\",\"d\":\"").append(checkDiff(one.sameCount)).append("\"},");
							tmp.append("\"downCount\":{\"v\":\"").append(stock.downCount).append("\",\"d\":\"").append(checkDiff(one.downCount)).append("\"}");
						    
							tmp.append("}");
						}

//						tmp.append("]");
					}
					
					tmp.append("],");
					
					tmp.append("\"index\":").append("\"").append(index + sendCount).append("\"");
				}
				else
				{
					tmp.append("\"push\":\"\"");
				}
			}
			else
			{
				tmp.append("\"push\":\"\"");
			}
			
			tmp.append("}");
			
			data = tmp.toString();
			PrintWriter out = response.getWriter();
		    out.println(data);
//		    System.out.println(data);
		}else if(event.equals("download")){

			response.setCharacterEncoding("utf-8");
			ArrayList<Stock[]>  stocks = CompareProcess.store;
			StringBuilder tmp = new StringBuilder();
			tmp.append("[");
			if(stocks.size() > 0){
				for(int i=0; i<stocks.size(); i++){
					if(i > 0) {
						tmp.append(",");
					}
					Stock[] stockList = stocks.get(i);
					Stock one = stockList[0];
					for(int j=1; j<stockList.length; j++){
						if(j != 1) {
							tmp.append(",");
						}
						
						tmp.append("{");
						Stock stock = stockList[j];
						tmp.append("\"border\":{\"v\":\"").append(j==1?"1":"0").append("\",\"d\":\"").append(j==stockList.length-1?"1":"0").append("\"},");
						tmp.append("\"host\":{\"v\":\"").append(stock.host).append("\",\"d\":\"").append(checkDiff(one.status)).append("\"},");
						tmp.append("\"responseTime\":{\"v\":\"").append(stock.responseTime).append("\",\"d\":\"").append(checkDiff(one.status)).append("\"},");
						tmp.append("\"id\":{\"v\":\"").append(stock.id).append("\",\"d\":\"").append(checkDiff(one.status)).append("\"},");
						tmp.append("\"name\":{\"v\":\"").append(stock.name).append("\",\"d\":\"").append(checkDiff(one.status)).append("\"},");

						
						tmp.append("\"status\":{\"v\":\"").append(stock.status).append("\",\"d\":\"").append(checkDiff(one.status)).append("\"},");
						tmp.append("\"datetime\":{\"v\":\"").append(stock.datetime).append("\",\"d\":\"").append(checkDiff(one.datetime)).append("\"},");
						tmp.append("\"market\":{\"v\":\"").append(stock.market).append("\",\"d\":\"").append(checkDiff(one.market)).append("\"},");
						tmp.append("\"subtype\":{\"v\":\"").append(stock.subtype).append("\",\"d\":\"").append(checkDiff(one.subtype)).append("\"},");
						tmp.append("\"lastPrice\":{\"v\":\"").append(stock.lastPrice).append("\",\"d\":\"").append(checkDiff(one.lastPrice)).append("\"},");
						tmp.append("\"highPrice\":{\"v\":\"").append(stock.highPrice).append("\",\"d\":\"").append(checkDiff(one.highPrice)).append("\"},");
						tmp.append("\"lowPrice\":{\"v\":\"").append(stock.lowPrice).append("\",\"d\":\"").append(checkDiff(one.lowPrice)).append("\"},");
						tmp.append("\"openPrice\":{\"v\":\"").append(stock.openPrice).append("\",\"d\":\"").append(checkDiff(one.openPrice)).append("\"},");
						tmp.append("\"preClosePrice\":{\"v\":\"").append(stock.preClosePrice).append("\",\"d\":\"").append(checkDiff(one.preClosePrice)).append("\"},");
						tmp.append("\"changeRate\":{\"v\":\"").append(stock.changeRate).append("\",\"d\":\"").append(checkDiff(one.changeRate)).append("\"},");
						tmp.append("\"volume\":{\"v\":\"").append(stock.volume).append("\",\"d\":\"").append(checkDiff(one.volume)).append("\"},");
						tmp.append("\"nowVolume\":{\"v\":\"").append(stock.nowVolume).append("\",\"d\":\"").append(checkDiff(one.nowVolume)).append("\"},");
						tmp.append("\"turnoverRate\":{\"v\":\"").append(stock.turnoverRate).append("\",\"d\":\"").append(checkDiff(one.turnoverRate)).append("\"},");
						tmp.append("\"limitUP\":{\"v\":\"").append(stock.limitUP).append("\",\"d\":\"").append(checkDiff(one.limitUP)).append("\"},");
						tmp.append("\"limitDown\":{\"v\":\"").append(stock.limitDown).append("\",\"d\":\"").append(checkDiff(one.limitDown)).append("\"},");
						tmp.append("\"averageValue\":{\"v\":\"").append(stock.averageValue).append("\",\"d\":\"").append(checkDiff(one.averageValue)).append("\"},");
						tmp.append("\"change\":{\"v\":\"").append(stock.change).append("\",\"d\":\"").append(checkDiff(one.change)).append("\"},");
						tmp.append("\"amount\":{\"v\":\"").append(stock.amount).append("\",\"d\":\"").append(checkDiff(one.amount)).append("\"},");
						tmp.append("\"volumeRatio\":{\"v\":\"").append(stock.volumeRatio).append("\",\"d\":\"").append(checkDiff(one.volumeRatio)).append("\"},");
						tmp.append("\"buyPrice\":{\"v\":\"").append(stock.buyPrice).append("\",\"d\":\"").append(checkDiff(one.buyPrice)).append("\"},");
						tmp.append("\"sellPrice\":{\"v\":\"").append(stock.sellPrice).append("\",\"d\":\"").append(checkDiff(one.sellPrice)).append("\"},");
						tmp.append("\"buyVolume\":{\"v\":\"").append(stock.buyVolume).append("\",\"d\":\"").append(checkDiff(one.buyVolume)).append("\"},");
						tmp.append("\"sellVolume\":{\"v\":\"").append(stock.sellVolume).append("\",\"d\":\"").append(checkDiff(one.sellVolume)).append("\"},");
						tmp.append("\"totalValue\":{\"v\":\"").append(stock.totalValue).append("\",\"d\":\"").append(checkDiff(one.totalValue)).append("\"},");
						tmp.append("\"flowValue\":{\"v\":\"").append(stock.flowValue).append("\",\"d\":\"").append(checkDiff(one.flowValue)).append("\"},");
						tmp.append("\"netAsset\":{\"v\":\"").append(stock.netAsset).append("\",\"d\":\"").append(checkDiff(one.netAsset)).append("\"},");
						tmp.append("\"pe\":{\"v\":\"").append(stock.pe).append("\",\"d\":\"").append(checkDiff(one.pe)).append("\"},");
						tmp.append("\"roe\":{\"v\":\"").append(stock.roe).append("\",\"d\":\"").append(checkDiff(one.roe)).append("\"},");
						tmp.append("\"capitalization\":{\"v\":\"").append(stock.capitalization).append("\",\"d\":\"").append(checkDiff(one.capitalization)).append("\"},");
						tmp.append("\"circulatingShares\":{\"v\":\"").append(stock.circulatingShares).append("\",\"d\":\"").append(checkDiff(one.circulatingShares)).append("\"},");
						tmp.append("\"buyPricesTmp\":{\"v\":\"").append(stock.buyPricesTmp).append("\",\"d\":\"").append(checkDiff(one.buyPricesTmp)).append("\"},");
						tmp.append("\"sellPricesTmp\":{\"v\":\"").append(stock.sellPricesTmp).append("\",\"d\":\"").append(checkDiff(one.sellPricesTmp)).append("\"},");
						tmp.append("\"buyVolumesTmp\":{\"v\":\"").append(stock.buyVolumesTmp).append("\",\"d\":\"").append(checkDiff(one.buyVolumesTmp)).append("\"},");
						tmp.append("\"buySingleVolumesTmp\":{\"v\":\"").append(stock.buySingleVolumesTmp).append("\",\"d\":\"").append(checkDiff(one.buySingleVolumesTmp)).append("\"},");
						tmp.append("\"sellVolumesTmp\":{\"v\":\"").append(stock.sellVolumesTmp).append("\",\"d\":\"").append(checkDiff(one.sellVolumesTmp)).append("\"},");
						tmp.append("\"sellSingleVolumesTmp\":{\"v\":\"").append(stock.sellSingleVolumesTmp).append("\",\"d\":\"").append(checkDiff(one.sellSingleVolumesTmp)).append("\"},");
						tmp.append("\"amplitudeRate\":{\"v\":\"").append(stock.amplitudeRate).append("\",\"d\":\"").append(checkDiff(one.amplitudeRate)).append("\"},");
						tmp.append("\"receipts\":{\"v\":\"").append(stock.receipts).append("\",\"d\":\"").append(checkDiff(one.receipts)).append("\"},");
						tmp.append("\"tradeTickTmp\":{\"v\":\"").append(stock.tradeTickTmp).append("\",\"d\":\"").append(checkDiff(one.tradeTickTmp)).append("\"},");
						tmp.append("\"upCount\":{\"v\":\"").append(stock.upCount).append("\",\"d\":\"").append(checkDiff(one.upCount)).append("\"},");
						tmp.append("\"sameCount\":{\"v\":\"").append(stock.sameCount).append("\",\"d\":\"").append(checkDiff(one.sameCount)).append("\"},");
						tmp.append("\"downCount\":{\"v\":\"").append(stock.downCount).append("\",\"d\":\"").append(checkDiff(one.downCount)).append("\"}");
					    
						tmp.append("}");
					}
					
				}
				tmp.append("],");
			}
			
			//去掉最后一个,
			String strtmp = tmp.toString();
			tmp.setLength(0);
			tmp.append(strtmp.substring(0, strtmp.length()-1));
			System.out.println(tmp.toString());
			JSONArray jArray = new JSONArray(tmp.toString());
			String path = ExcelUtil.processExcelQuote(jArray,request.getServletContext());
			response.setHeader("content-disposition", "attachment;filename=quote"+System.currentTimeMillis()+".xls");
			InputStream in = new FileInputStream(path);
			int len = 0;
			byte[] buffer = new byte[1024];
	         //6.通过response对象获取OutputStream流
	        OutputStream out = response.getOutputStream();
	         //7.将FileInputStream流写入到buffer缓冲区
		    while ((len = in.read(buffer)) > 0) {
		      //8.使用OutputStream将缓冲区的数据输出到客户端浏览器
		        out.write(buffer,0,len);
		    }
		    in.close();

		
		}
//		else if(event.equals("t"))
//		{
//			StringBuilder tmp = new StringBuilder();
//			tmp.append("{");
//			tmp.append("\"code\":\"00000\",");
//			tmp.append("\"message\":\"ok\",");
//			tmp.append("\"running\":");
//			tmp.append(quoteCompareTask.isRunning() ? "\"true\"" : "\"false\"");
//			tmp.append("}");
//			
//			data = tmp.toString();
//		}
//		else if(event.equals("p"))
//		{
//			ArrayList<ArrayList<Stock>> push = QuoteCompare.store;
//			
//			StringBuilder tmp = new StringBuilder();
//			
//			if(push.size() > 0)
//			{
//				int index = Integer.parseInt(src);
//				
//				if(push.size() > 0)
//				{
//					tmp.append("{");
//					tmp.append("\"code\":\"00000\",");
//					tmp.append("\"message\":\"ok\",");
//					tmp.append("\"push\":[");
//
//					for(int i = index + 1 ; i < push.size() ; i++)
//					{
//						tmp.append("[");
//						
//						ArrayList<Stock> list = push.get(i);
//						
//						for(int k = 0 ; k < list.size() ; k++)
//						{
//							tmp.append("{");
//							
//							Stock stock = list.get(k);
//							
//							tmp.append("\"host\":\"").append(stock.host).append("\",");
//							tmp.append("\"responseTime\":\"").append(stock.responseTime).append("\",");
//							tmp.append("\"id\":\"").append(stock.id).append("\",");
//							tmp.append("\"name\":\"").append(stock.name).append("\",");
//							tmp.append("\"status\":\"").append(stock.status).append("\",");
//							tmp.append("\"datetime\":\"").append(stock.datetime).append("\",");
//							tmp.append("\"market\":\"").append(stock.market).append("\",");
//							tmp.append("\"subtype\":\"").append(stock.subtype).append("\",");
//							tmp.append("\"lastPrice\":\"").append(stock.lastPrice).append("\",");
//							tmp.append("\"highPrice\":\"").append(stock.highPrice).append("\",");
//							tmp.append("\"lowPrice\":\"").append(stock.lowPrice).append("\",");
//							tmp.append("\"openPrice\":\"").append(stock.openPrice).append("\",");
//							tmp.append("\"preClosePrice\":\"").append(stock.preClosePrice).append("\",");
//							tmp.append("\"changeRate\":\"").append(stock.changeRate).append("\",");
//							tmp.append("\"volume\":\"").append(stock.volume).append("\",");
//							tmp.append("\"nowVolume\":\"").append(stock.nowVolume).append("\",");
//							tmp.append("\"turnoverRate\":\"").append(stock.turnoverRate).append("\",");
//							tmp.append("\"limitUP\":\"").append(stock.limitUP).append("\",");
//							tmp.append("\"limitDown\":\"").append(stock.limitDown).append("\",");
//							tmp.append("\"averageValue\":\"").append(stock.averageValue).append("\",");
//							tmp.append("\"change\":\"").append(stock.change).append("\",");
//							tmp.append("\"amount\":\"").append(stock.amount).append("\",");
//							tmp.append("\"volumeRatio\":\"").append(stock.volumeRatio).append("\",");
//							tmp.append("\"buyPrice\":\"").append(stock.buyPrice).append("\",");
//							tmp.append("\"sellPrice\":\"").append(stock.sellPrice).append("\",");
//							tmp.append("\"buyVolume\":\"").append(stock.buyVolume).append("\",");
//							tmp.append("\"sellVolume\":\"").append(stock.sellVolume).append("\",");
//							tmp.append("\"totalValue\":\"").append(stock.totalValue).append("\",");
//							tmp.append("\"flowValue\":\"").append(stock.flowValue).append("\",");
//							tmp.append("\"netAsset\":\"").append(stock.netAsset).append("\",");
//							tmp.append("\"pe\":\"").append(stock.pe).append("\",");
//							tmp.append("\"roe\":\"").append(stock.roe).append("\",");
//							tmp.append("\"capitalization\":\"").append(stock.capitalization).append("\",");
//							tmp.append("\"circulatingShares\":\"").append(stock.circulatingShares).append("\",");
//							tmp.append("\"buyPricesTmp\":\"").append(stock.buyPricesTmp).append("\",");
//							tmp.append("\"sellPricesTmp\":\"").append(stock.sellPricesTmp).append("\",");
//							tmp.append("\"buyVolumesTmp\":\"").append(stock.buyVolumesTmp).append("\",");
//							tmp.append("\"buySingleVolumesTmp\":\"").append(stock.buySingleVolumesTmp).append("\",");
//							tmp.append("\"sellVolumesTmp\":\"").append(stock.sellVolumesTmp).append("\",");
//							tmp.append("\"sellSingleVolumesTmp\":\"").append(stock.sellSingleVolumesTmp).append("\",");
//							tmp.append("\"amplitudeRate\":\"").append(stock.amplitudeRate).append("\",");
//							tmp.append("\"receipts\":\"").append(stock.receipts).append("\",");
//						    
//							tmp.append("},");
//						}
//						
//						tmp.append("],");
//					}
//					
//					tmp.append("]}");
//				}
//				else
//				{
//					tmp.append("{");
//					tmp.append("\"code\":\"00000\",");
//					tmp.append("\"message\":\"ok\",");
//					tmp.append("\"push\":\"\"}");
//				}
//			}
//			else
//			{
//				tmp.append("{");
//				tmp.append("\"code\":\"00000\",");
//				tmp.append("\"message\":\"ok\",");
//				tmp.append("\"push\":\"\"}");
//			}
//			
//			data = tmp.toString();
//		}
		
	}
	
	private String checkDiff(String s)
	{
		if(s != null && s.indexOf("@") > -1)
		{
			return "Y";
		}
		else
		{
			return "N";
		}
	}
	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		doGet(request, response);
	}
}
